﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CitizenJournalismNetworkServer.Attributes
{

    public class SerializationBooleanRepresentationAttribute: Attribute
    {
        public enum BooleanRepresentation
        {
            YesNo,
            TrueFalse,
            OneZero
        }

        public const string BooleanYes = "yes";
        public const string BooleanNo = "no";
        public const string BooleanTrue = "true";
        public const string BooleanFalse = "false";
        public const string BooleanOne = "1";
        public const string BooleanZero = "0";

        public BooleanRepresentation Representation { get; set; }

        public SerializationBooleanRepresentationAttribute(BooleanRepresentation representation)
        {
            this.Representation = representation;
        }

        public string SerializeValue(bool value)
        {
            switch (this.Representation)
            {
                case BooleanRepresentation.OneZero:
                    return (value == true) ? BooleanOne : BooleanZero;
                case BooleanRepresentation.TrueFalse:
                    return (value == true) ? BooleanTrue : BooleanFalse;
                default:
                    return (value == true) ? BooleanYes : BooleanNo;
            }
        }

    }
}